package com.notice.viewmodel;

import com.notice.model.UserModel;
import com.notice.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

@Component
public class UserViewModel extends BaseViewModel {
    
    @Autowired
    private UserRepository userRepository;
    
    private UserModel currentUser;
    
    public void login(String uid, String password) {
        System.out.println("Attempting login with uid: " + uid);
        UserModel user = userRepository.findByUidAndPassword(uid, password);
        System.out.println("Login result: " + (user != null ? "success" : "failed"));
        if(user != null) {
            this.currentUser = user;
            notifyStateChanged();
        }
    }
    
    public boolean register(UserModel user) {
        return userRepository.save(user);
    }
    
    public List<UserModel> getAllUsers() {
        return userRepository.findAll();
    }
    
    public boolean deleteUser(String uid) {
        return userRepository.delete(uid);
    }
    
    public boolean updateUser(UserModel user) {
        return userRepository.update(user);
    }
    
    public UserModel getCurrentUser() {
        return currentUser;
    }
} 